package com.qhit.service.impl;

import com.qhit.dao.GoodsMapper;
import com.qhit.pojo.Goods;
import com.qhit.pojo.Role;
import com.qhit.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: lyb
 * @description: ll
 * @author: DYF
 * @create: 2020-10-22 10:12
 */
@Service
public class GoodsServiceImpl implements GoodsService {

    @Autowired
    private GoodsMapper goodsMapper;

    public List<Goods> getList(HashMap hashMap) {
        return goodsMapper.getList(hashMap);
    }

    public long getListCount(HashMap hashMap) {
        return goodsMapper.getListCount(hashMap);
    }

    public int add(Goods goods) {
        return goodsMapper.add(goods);
    }

    public Goods getGoodsById(String id) {
        return goodsMapper.getGoodsById(id);
    }

    public int edit(Goods goods) {
        return goodsMapper.edit(goods);
    }

    public int del(String id) {
        return goodsMapper.del(id);
    }

    @Override
    public Map getListByPageWithSize(Integer page, Integer pageSize, String keywords) {

        HashMap hashMap = new HashMap();
        hashMap.put("keywords",keywords);

        hashMap.put("page",page);
        hashMap.put("start",(page-1)*pageSize);
        hashMap.put("pageSize",pageSize);

        List<Goods> goods= goodsMapper.getList(hashMap);
        long total= goodsMapper.getListCount(hashMap);

        hashMap.put("totalPage",(total%pageSize==0)?(total/pageSize):(total/pageSize+1));


        HashMap result = new HashMap();
        result.put("hashMap",hashMap);
        result.put("goodsList",goods);

        return result;
    }

}
